package com.集合.Map___;

import com.polymorphic多态.练习题.练习01.E;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("all")
public class MapExercise01 {
    public static void main(String[] args) {
        /**
         * 添加三个员工，键 id 值 员工对象
         * 取出工资大于18000的员工信息；
         */
        HashMap hashMap = new HashMap();
        hashMap.put(1,new Employee("张飞",35,18999));
        hashMap.put(2,new Employee("jeak",20,10000));
        hashMap.put(3,new Employee("messi",38,33333));
        Set keyset = hashMap.keySet();

        System.out.println("===========第一种遍历方式iterator=========");
        Iterator iterator = keyset.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            if(((Employee)hashMap.get(key)).getSalary() >= 18000 )
                System.out.println(((Employee)hashMap.get(key)).getName());
        }

        System.out.println("===========第二种遍历方式增强for===================");
        for (Object key : keyset) {
            if(((Employee)hashMap.get(key)).getSalary() >= 18000 )
                System.out.println(((Employee)hashMap.get(key)).getName());
        }

        System.out.println("===========第三种遍历方式entrySet=========");
        Set entrySet = hashMap.entrySet();
        for (Object Node : entrySet) {
            Map.Entry map = (Map.Entry) Node;//Object向下成Entry对象，调用其getValue方法，得到value后
            if(((Employee)map.getValue()).getSalary() >= 18000)//再把Entry对象value转型成Employee对象，调用getSalaru
                System.out.println(((Employee)map.getValue()).getName());

        }
    }
}

@SuppressWarnings("all")
class Employee {
    private String name;
    private int age;
    private double salary;

    public Employee(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public double getSalary() {
        return salary;
    }

    @Override
    public String toString() {
        return name;
    }
}
